/* GUI CONVERTED from rqapmt.p (converter v1.76) Tue Mar 19 08:25:16 2002 */
/* rqapmt.p   - REQUISITION APPROVAL                                          */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.13.1.7 $                                                      */
/*V8:ConvertMode=Maintenance                                                  */
/* Revision: 8.6    LAST MODIFIED BY: 05/05/97  By: B. Gates          *J1Q2*  */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane            */
/* REVISION: 8.6E   LAST MODIFIED: 03/13/98   BY: B. Gates *J2GM*             */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan           */
/* REVISION: 8.6E   LAST MODIFIED: 06/11/98   BY: *L040* Charles Yen          */
/* REVISION: 8.5    LAST MODIFIED: 09/13/98   BY: *J301* Patrick Rowan        */
/* REVISION: 8.6E   LAST MODIFIED: 01/13/99   BY: *J38J* Steve Nugent         */
/* REVISION: 8.6E   LAST MODIFIED: 09/09/99   BY: *J39R* Reetu Kapoor         */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown           */
/* Revision: 1.13.1.4       BY: Indu Arora        DATE: 06/07/01  ECO: *N0YZ* */
/* Revision: 1.13.1.5       BY: Jean Miller       DATE: 03/04/02  ECO: *N1BS* */
/* $Revision: 1.13.1.7 $    BY: Jean Miller       DATE: 03/06/02  ECO: *N1BW* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "b+ "}

{rqconst.i}

define new shared variable approver like rqa_apr no-undo.
define new shared variable what_to_view as logical
   label "View Queue/Dispositioned" format "Queue/Dispositioned"
   initial true no-undo.
define new shared variable cmtindx as integer.
define variable approvals_completed as log no-undo.
define variable reqnbr    like rqm_mstr.rqm_nbr.
define variable continue  as logical no-undo.
define variable route_req as logical no-undo.
define variable alternate_ok as logical no-undo.
define variable all_info_correct like mfc_logical no-undo.

define variable QUEUE as logical initial true no-undo.
define variable DISPOSITIONED as logical initial false no-undo.
define variable APPROVED as logical initial false no-undo.

define variable view_requisition like mfc_logical
   label "View Requisition" no-undo.
define variable modify_requisition like mfc_logical
   label "Modify Requistion" no-undo.
define variable approval_comments like mfc_logical
   label "Maintain Aprvl Comments" no-undo.
define variable date_time as character no-undo.
define variable exchg_rate as decimal no-undo.
define variable exchg_rate2 as decimal no-undo.
define variable exch-error-number like msg_nbr no-undo.
define variable l_option as character format "x(36)".
define variable other-browse as character no-undo.

{rqalttd.i new} /*APPROVER LIST TEMPTABLE DEFINITIONS*/


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
what_to_view            colon 30
   approver                colon 30
   usr_name                no-label
   reqnbr                  colon 30
   skip(1)
   view_requisition        colon 30
   modify_requisition      colon 30
   approval_comments       colon 30
   action_entry            colon 30 format "x(1)"
   l_option                no-label
 SKIP(.4)  /*GUI*/
with frame a attr-space side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

l_option:screen-value in frame a =
    "1=" + getTermLabel("APPROVE",10) +
   " 2=" + getTermLabel("DENY",8) +
   " 3=" + getTermLabel("REVERSE",10).

find first gl_ctrl no-lock.

/*GET MOST RECENTLY ACCESSED REQ NUMBER AND DISPLAY*/
{gprun.i ""rqidf.p""
   "(input 'get', input 'reqnbr', input-output reqnbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


display reqnbr with frame a.

/*GET MOST RECENTLY ACCESSED APPROVER AND DISPLAY*/
{gprun.i ""rqidf.p""
   "(input 'get', input 'approver', input-output approver)"}
/*GUI*/ if global-beam-me-up then undo, leave.


if approver = "" then approver = global_userid.
display approver with frame a.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


      update what_to_view with frame a.

      /* Determine which lookup to run */
      if what_to_view then
         other-browse = "".
      else
         other-browse = "rqlu013.p".
      {gprun.i ""gpbranch.p""
         "(input 'rqlu012.p', input other-browse)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         set approver with frame a
         editing:
            {mfnp.i usr_mstr
               approver usr_userid approver usr_userid usr_userid}

            if recno <> ? then do:
               display
                  usr_userid @ approver
                  usr_name
               with frame a.
            end.
         end.

         find usr_mstr where usr_userid = approver no-lock no-error.

         if not available usr_mstr then do:
            /*USER ID DOES NOT EXIST*/
            {pxmsg.i &MSGNUM=5065 &ERRORLEVEL=3}
            undo, retry.
         end.

         display usr_name with frame a.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /*PASS APPROVER VALUE TO LOOKUP BROWSES*/
      {gpbrparm.i &browse=rqlu012.p &parm=c-brparm1 &val=approver}
      {gpbrparm.i &browse=rqlu013.p &parm=c-brparm1 &val=approver}

      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         set reqnbr with frame a editing:
            if what_to_view = DISPOSITIONED then do:
               /*LOOK AT THE APPROVER DETAIL FILE FOR EXT'G
                 APPROVALS/DENIALS*/
               {mfnp05.i rqda_det
                  rqda_apr_userid
                  "rqda_apr_userid = approver"
                  rqda_nbr
                  "input frame a reqnbr"}

               if recno <> ? then
                  display rqda_nbr @ reqnbr with frame a.

            end. /* if what_to_view = DISPOSITIONED */

         else do:
               /*LOOK AT REQS ROUTED TO THIS APPROVER*/
               {mfnp05.i rqm_mstr
                  rqm_rtto
                  "rqm_rtto_userid = approver and rqm_open"
                  rqm_nbr
                  "input frame a reqnbr"}

               if recno <> ? then
                  display rqm_nbr @ reqnbr with frame a.

            end.

         end.

         find rqm_mstr where rqm_nbr = reqnbr exclusive-lock no-error.

         if not available rqm_mstr then do:
            /* REQUISITION DOES NOT EXIST */
            {pxmsg.i &MSGNUM=193 &ERRORLEVEL=3}
            undo, retry.
         end.

         if rqm_status <> LINE_STATUS_OPEN then do:

            if rqm_status = LINE_STATUS_CLOSED
            then do:
               /* REQUISITION IS CLOSED */
               {pxmsg.i &MSGNUM=3325 &ERRORLEVEL=3}
               undo, retry.
            end.

            else do:
               /* REQUISITION IS CANCELLED */
               {pxmsg.i &MSGNUM=2118 &ERRORLEVEL=3}
               undo, retry.
            end.

         end.

         if rqm_rtdto_purch then do:
            /*REQUISITION ROUTED TO PURCHASING*/
            {pxmsg.i &MSGNUM=2106 &ERRORLEVEL=2}
         end.

         /*ENSURE CURRENT EXCHANGE RATE TO APPROVAL CURRENCY*/
         find first rqf_ctrl no-lock.
         {gprun.i ""rqexrt.p""
                   "(input rqm_curr,
                     input rqf_appr_curr,
                     input rqm_ex_ratetype,
                     output exchg_rate,
                     output exchg_rate2,
                     output exch-error-number)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if exch-error-number <> 0 then do:
            /*NO EXCHANGE RATE FOR APPROVAL CURRENCY*/
            {pxmsg.i &MSGNUM=2087 &ERRORLEVEL=3}
            undo, retry.
         end.

         if approver <> rqm_rtto_userid then do:
            /*REQUISITION CURRENTLY ROUTED TO*/
            {pxmsg.i &MSGNUM=2094 &ERRORLEVEL=2 &MSGARG1=rqm_rtto_userid}
         end.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /*SAVE ACCESSED REQ NUMBER FOR OTHER PGMS TO USE*/
      {gprun.i ""rqidf.p""
         "(input 'put', input 'reqnbr', input-output reqnbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /*SAVE APPROVER ID FOR OTHER PGMS TO USE*/
      {gprun.i ""rqidf.p""
         "(input 'put', input 'approver', input-output approver)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      display
         view_requisition
         modify_requisition
         approval_comments
      with frame a.

      if what_to_view = QUEUE then
         display "1" @ action_entry with frame a.
      else
         display "3" @ action_entry with frame a.

      hide message no-pause.

      /*BUILDING APPROVER LIST...*/.
      {pxmsg.i &MSGNUM=2078 &ERRORLEVEL=1}
      {gprun.i ""rqbal.p"" "(input recid(rqm_mstr))"}
/*GUI*/ if global-beam-me-up then undo, leave.

      hide message no-pause.

      if approver <> rqm_rtto_userid then do:
         /*REQUISITION CURRENTLY ROUTED TO*/
         {pxmsg.i &MSGNUM=2094 &ERRORLEVEL=2 &MSGARG1=rqm_rtto_userid}
      end.

      /*VIEW REQUISITION DETAIL IF REQUESTED */
      set view_requisition with frame a.

      if view_requisition then do:
         hide frame a no-pause.
         {gprun.i ""hkrqrqiq1a.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         view frame a.
      end.

      /*MODIFY REQUISITION IF REQUESTED*/
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         set modify_requisition with frame a.

         if modify_requisition and global_userid <> approver then do:
            {gprun.i ""rqckalt.p""
               "(input approver, input global_userid,
                 output alternate_ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            if not alternate_ok then do:
               for each rqa_mstr where
                  rqa_apr = approver no-lock:
                  if global_userid = rqa_alt_apr[1] or
                     global_userid = rqa_alt_apr[2] or
                     global_userid = rqa_admin_apr
                  then
                     alternate_ok = true.
               end. /* for each rqa_mstr */
            end. /* if not alternate_ok */

            if not alternate_ok then do:
               /*YOU ARE NOT AN ALTERNATE FOR THIS APPROVER*/
               {pxmsg.i &MSGNUM=2073 &ERRORLEVEL=3}
               undo, retry.
            end.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if modify_requisition then do:
         hide frame a no-pause.
         {gprun.i ""rqrqmt0.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         view frame a.
      end.

      /*ENTER APPROVAL COMMENTS IF REQUESTED*/
      set approval_comments with frame a.

      if approval_comments then do:
         assign
            global_ref = rqm_vend
            cmtindx = rqm_apr_cmtindx.
         {gprun.i ""gpcmmt01.p"" "(input ""rqm_mstr"")"}
/*GUI*/ if global-beam-me-up then undo, leave.

         rqm_apr_cmtindx = cmtindx.
      end.

      /*GET THE DESIRED ACTION*/
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         set action_entry with frame a.

         if action_entry <> ACTION_APPROVE
            and action_entry <> ACTION_DENY
            and action_entry <> ACTION_REVERSE
         then do:
            /* Invalid Action */
            {pxmsg.i &MSGNUM=2052 &ERRORLEVEL=3}
            undo, retry.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /*WARN IF THE APPROVER ALREADY APPROVED/DENIED*/
      if action_entry = ACTION_APPROVE
      or action_entry = ACTION_DENY
      then do:

         find rqda_det where rqda_nbr = rqm_nbr
            and rqda_apr_userid = approver
            no-lock no-error.

         if available rqda_det then do:
            date_time = string(rqda_date) + " " +
                        string(rqda_time,"HH:MM:SS").

            if rqda_action = ACTION_APPROVE then do:
               /*YOU APPROVED THIS REQUISITION...*/
               {pxmsg.i &MSGNUM=2071 &ERRORLEVEL=2 &MSGARG1=date_time}
            end.
            else do:
               /*YOU DENIED THIS REQUISITION...*/
               {pxmsg.i &MSGNUM=2072 &ERRORLEVEL=2 &MSGARG1=date_time}
            end.
         end.
      end.

      /*CHECKS REVERSALS*/
      if action_entry = ACTION_REVERSE then do:

         find rqda_det where rqda_nbr = rqm_nbr
                         and rqda_apr_userid = approver
         no-lock no-error.

         if not available rqda_det then do:
            /*YOU HAVE NOT APPROVED/DENIED THIS REQUISITION*/
            {pxmsg.i &MSGNUM=2067 &ERRORLEVEL=3}
            undo, retry.
         end.

         if global_userid <> approver
            and rqda_ent_userid <> global_userid
         then do:
            /*YOU DID NOT ENTER THE APPROVAL/DENIAL FOR THIS APPROVER*/
            {pxmsg.i &MSGNUM=2068 &ERRORLEVEL=3}
            undo, retry.
         end.
      end.

      /*CHECKS FOR ALTERNATE/ADMIN APPROVERS.  THE 3RD REQUIREMENT
        IS BECAUSE THE ENTERER IS ALWAYS AN ALTERNATE FOR THE
        REQUESTER.*/

      if (action_entry = ACTION_APPROVE or action_entry = ACTION_DENY) and
         global_userid <> approver and
         not (global_userid = rqm_eby_userid and approver = rqm_rqby_userid)
      then do:

         {gprun.i ""rqckalt.p""
            "(input approver, input global_userid, output alternate_ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if not alternate_ok then do:
            for each rqa_mstr where
                  rqa_apr = approver no-lock:
               if global_userid = rqa_alt_apr[1] or
                  global_userid = rqa_alt_apr[2] or
                  global_userid = rqa_admin_apr
               then
                  alternate_ok = true.
               else
                  alternate_ok = false.
            end. /* for each rqa_mstr */
         end. /* if not alternate_ok */

         if not alternate_ok then do:
            /*YOU ARE NOT AN ALTERNATE FOR THIS APPROVER*/
            {pxmsg.i &MSGNUM=2073 &ERRORLEVEL=3}
            undo, retry.
         end.
      end.

      /*ASK IF OK TO DO IT*/
      all_info_correct = true.
      /* Is all information correct */
      {pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=all_info_correct}
      if not all_info_correct then undo, leave.

      /*LET'S DO IT*/
      if action_entry = ACTION_APPROVE
      or action_entry = ACTION_DENY
      then do:

         /*CREATE APPROVAL RECORD IF NECESSARY AND MARK WITH APPROVE
           OR DENY*/
         find rqda_det where rqda_nbr = rqm_nbr
            and rqda_apr_userid = approver
            exclusive-lock no-error.

         if not available rqda_det then do:
            create rqda_det.
            assign
               rqda_nbr = rqm_nbr
               rqda_apr_userid = approver.

            if recid(rqda_det) = -1 then.
         end.

         assign
            rqda_action = action_entry
            rqda_date = today
            rqda_time = time.

         /*MARK THE COMBINED APPROVER LIST RECORD WITH
           APPROVAL STATUS*/

         find ttcal where ttcal_apr_userid = approver no-lock no-error.

         if not available ttcal then do:
            create ttcal.
            assign
               ttcal_apr_userid = rqda_apr_userid
               ttcal_required = false.
         end.

         assign
            ttcal_apr_date = rqda_date
            ttcal_apr_time = rqda_time
            ttcal_apr_action = rqda_action.

         /*UPDATE THE REQUISITION APPROVAL STATUS*/
         {gprun.i ""rqcfa.p""
            "(input rqm_nbr, output approvals_completed)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if approvals_completed then do:
            for each rqd_det exclusive-lock
                  where rqd_nbr = rqm_nbr:
               rqd_aprv_stat = APPROVAL_STATUS_APPROVED.
            end.

            rqm_aprv_stat = APPROVAL_STATUS_APPROVED.
         end.

         /*WRITE HISTORY RECORD*/
         {gprun.i ""rqwrthst.p""
                "(input rqm_nbr,
                  input 0,
                  input action_entry,
                  input approver,
                  input '',
                  input '')"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      else
      if action_entry = ACTION_REVERSE then do:

         /*FOR REVERSAL WE SIMPLY DELETE THE APPROVAL RECORD*/
         find rqda_det where rqda_nbr = rqm_nbr
            and rqda_apr_userid = approver
         exclusive-lock no-error.

         if available rqda_det then delete rqda_det.

         /*WRITE HISTORY RECORD*/
         {gprun.i ""rqwrthst.p""
                "(input rqm_nbr,
                  input 0,
                  input action_entry,
                  input approver,
                  input '',
                  input '')"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*transaction*/

   /*GET NEXT ROUTE-TO*/
   if all_info_correct then do:

      route_req = rqm_rtto_userid = approver.
      /* Route this Requisition */
      {pxmsg.i &MSGNUM=2083 &ERRORLEVEL=1 &CONFIRM=route_req}

      if route_req then do:
         {gprun.i ""rqrtmt0.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

   end.  /*END - if all_info_correct */

end.
/*GUI*/ if global-beam-me-up then undo, leave.


hide frame a no-pause.
